package dahuiji.common.dao;

import org.apache.log4j.Logger;
import org.hibernate.Session;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;

import dahuiji.common.lister.ParamIntialListener;

public class BaseDaoAbstract {
	static Logger log = Logger.getLogger(BaseDaoAbstract.class);

	public static SessionFactory sessionFactoryf;

	static {
		try {
			if (sessionFactoryf == null) {
				Configuration cfg = new Configuration().configure();
				cfg.configure();
				sessionFactoryf = cfg.buildSessionFactory();
			}

		} catch (Exception e) {
			log.warn("sessionFactoryf初始化失败");
			System.out.println(e);
		}
	}

	public BaseDaoAbstract() {

	}

	public SessionFactory getSessionFactory() {
		if (sessionFactoryf != null) {
			return sessionFactoryf;
		} else {
			Configuration cfg = new AnnotationConfiguration();
			cfg.configure();
			sessionFactoryf = cfg.buildSessionFactory();
			return sessionFactoryf;
		}

	}
}
